package club.babyf.nativeai;

import java.util.UUID;

/**
 * Test.
 *
 * @author zhanglei.
 * @date 2025/8/9 09:51.
 * @description TODO.
 */
public class Test {

    public static class Account {

        String name;

        int amount;

        @Override
        public String toString() {
            return "Account{" +
                    "name='" + name + '\'' +
                    ", amount=" + amount +
                    '}';
        }

    }

    public static class Log {

        String primaryKey;

        String accountName;

        int amount;

        Type type;

        @Override
        public String toString() {
            return "Log{" +
                    "primaryKey='" + primaryKey + '\'' +
                    ", accountName='" + accountName + '\'' +
                    ", amount=" + amount +
                    ", type=" + type +
                    '}';
        }

    }

    public static enum Type {

        OUT,

        ENTRY,

        ;

    }

    public void out(Account account, int x, String primaryKey) {
        String orgAccountName = account.name;
        int orgAccountAmount = account.amount;
        int amount = orgAccountAmount - x;
        account.amount = amount;
        // 进行数据持久化

        Log log = new Log();
        log.primaryKey = primaryKey;
        log.accountName = orgAccountName;
        log.amount = x;
        log.type = Type.OUT;
        // 进行数据持久化
        System.out.println("转出记录：" + log);
    }

    public void entry(Account account, int x, String primaryKey) {
        String targetAccountName = account.name;
        int targetAccountAmount = account.amount;
        int amount = targetAccountAmount + x;
        account.amount = amount;
        // 进行数据持久化

        Log log = new Log();
        log.primaryKey = primaryKey;
        log.accountName = targetAccountName;
        log.amount = x;
        log.type = Type.ENTRY;
        // 进行数据持久化
        System.out.println("转入记录：" + log);
    }

    public void trans(Account orgAccount, Account targetAccount, int x, String primaryKey) {
        out(orgAccount, x, primaryKey);
        entry(targetAccount, x, primaryKey);
    }

    public static void main(String[] args) {
        Test test = new Test();

        Account a = new Account();
        a.name = "a";
        a.amount = 100;
        System.out.println("转出前 - 转出账户：" + a);

        Account b = new Account();
        b.name = "b";
        b.amount = 100;
        System.out.println("转出前 - 转入账户：" + b);

        System.out.println(" ------------------------------ ");

        String primaryKey = UUID.randomUUID().toString();
        test.trans(a, b, 20, primaryKey);

        System.out.println(" ------------------------------ ");

        System.out.println("转出后 - 转出账户：" + a);
        System.out.println("转出后 - 转入账户：" + b);
    }

}
